<?php
namespace App\Http\Controllers\Property;

use App\Common\json;
use App\Common\SmsClient;
use App\Http\Controllers\Controller;
use App\Libraries\upload;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class MytipController extends  Controller{

    public function Allmytip(Request $request){
        if($request ->isMethod('get')){
            $data     = DB::table('secret')
                ->select('secret_id','secret_name','secret_image')
                ->get();
            if($data == true){
                return json::json('success', '修改成功', $data);
            }else{
                return json::json('failure','由于网络或者不正当原因失败',json::value(2));
            }
        }
    }

    public  function primary($release_id){
        $data = DB::table('secret')
            ->select('secret_id','secret_name','secret_content','secret_image')
            ->where('secret_id',$release_id)
            ->get();
        return $data;
    }

    public function Selectmytip(Request $request){
        if($request ->isMethod('post')){
            $hottopic_id       = $request ->input('secret_id');
            $data              = $this ->primary($hottopic_id);
            foreach ($data as $value){
                $hottopic_title =$value ->secret_name;
                $hottopic_content = $value ->secret_content;
                if(empty($value ->secret_image)){
                    $hottopic_image  = [];
                }else {
                    $hottopic_image = explode(',', $value ->secret_image);
                }
                $particulars ="http://www.mukitech.com/wuye/app/public/property/Mytip/$hottopic_id";
                // header("Content-Type: text/html; charset=utf-8");
                // $html_content = file_get_contents($particulars);
                // $H5               = file_get_contents()
/*                $secondary        = $this ->secondary($id);
                foreach ($secondary as $key){
                    $head      = $key ->head;
                    $nickname  = $key ->nickname;
                    $content    = $key ->content;
                    $time   = $key  ->hottopicreply_creation_time;
                    $lk[] = array('head'=>$head,'nickname'=>$nickname,'content'=>$content,'time'=>$time);
                }
                if(empty($lk)) {
                    $da = array('hottopic_title' => $hottopic_title, 'hottopic_content' => $hottopic_content, 'hottopic_image' => $hottopic_image,'H5'=>$particulars);
                }else{*/
                    $da = array('secret_name' => $hottopic_title, 'secret_content' => $hottopic_content, 'secret_image' => $hottopic_image,
                        'H5'=>$particulars);
             //   }
            }
            if($data == true){
                return json::json('success', '信息获取成功', $da);
            }else{
                return json::json('failure','由于网络或者不正当原因失败',json::value(1));
            }
        }
    }


}